package com.hengxinguotong.hxgtwygsp.ui.revenue.allocate;

import android.content.res.Resources;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.Allocate;
import com.hengxinguotong.hxgtwygsp.ui.base.BaseTabFragment;
import com.hengxinguotong.hxgtwygsp.widget.RecycleViewDivider;
import com.hengxinguotong.hxgtwygsp.widget.RingView;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

public class AllocateFragment extends BaseTabFragment implements AllocateContract.IView
{
    @Inject
    AllocateContract.IPresenter mPresenter;
    @BindView(R.id.allocate_year)
    TextView allocateYear;
    @BindView(R.id.mRingView)
    RingView mRingView;
    @BindView(R.id.allocate_recycle)
    RecyclerView allocateRecycle;

    private List<Allocate> allocateList = new ArrayList<>();
    private AllocateAdapter allocateAdapter;

    @Inject
    public AllocateFragment()
    {
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState)
    {
        super.onActivityCreated(savedInstanceState);
        mPresenter.bindView(this);
    }

    @Override
    public void onDestroy()
    {
        super.onDestroy();
        mPresenter.dropView();
    }

    @Override
    public int getLayoutResId()
    {
        return R.layout.fragment_allocate;
    }

    @Override
    public void init()
    {
       mockView();
        LinearLayoutManager llm = new LinearLayoutManager(getContext());
        llm.setOrientation(LinearLayoutManager.VERTICAL);
        allocateRecycle.setLayoutManager(llm);
        allocateRecycle.addItemDecoration(new RecycleViewDivider(getContext())
                .height(getResources().getDimensionPixelSize(R.dimen.px_30)));
        allocateAdapter = new AllocateAdapter(R.layout.item_allocate,allocateList);
        allocateRecycle.setAdapter(allocateAdapter);
    }

    private void mockView() {

        allocateYear.setText(String.format(getString(R.string.budget_year),2018));

        allocateList.add(new Allocate(0,"弥补物业费不足",18230.40 ));
        allocateList.add(new Allocate(1,"电梯维修",51449.50  ));
        allocateList.add(new Allocate(2,"税费",2258.56  ));
        allocateList.add(new Allocate(3,"其他",0.00 ));

        Resources resources = getResources();
        int[] colors = {resources.getColor(R.color.cD1B83B),resources.getColor(R.color.c019FFF), resources.getColor(R.color.c7250FC)};
        mRingView.setColors(colors);
        float[] values = {18230.40f, 51449.50f ,2258.56f};
        mRingView.setValues(values);

    }

    @OnClick({R.id.allocate_left, R.id.allocate_right})
    public void onViewClicked(View view)
    {
        switch (view.getId())
        {
            case R.id.allocate_left:
                break;
            case R.id.allocate_right:
                break;
        }
    }

}
